<template>
	<div id="app-ninenr">
			<ul class="nine-footer">
				<li><span>价格 ￥</span><span v-text="shopxinxi.price">69.00</span></li>
				<li v-if="userStute==1"><span>佣金 ￥</span><span v-text="shopxinxi.commission">5.00</span></li>
				<li v-if="userStute==0"><span>出售 </span><span v-text="shopxinxi.sales">1008</span><span>件</span></li>
				<li id="fxzyxx" v-if="userStute==1" @click="fxzy()"><img src="../img-ninewei/icon_share@3x.png"/>分享赚佣</li>
				<li v-if="userStute==0"><router-link :to="{name:'shopXQ',params:{id:goods_id}}"><img src="../img-ninewei/icon_see@3x.png"/>查看详情</router-link></li>
			</ul>
			<div class="tuwenxianqin-ctrl">
				<h3 v-text="shopxinxi.title"></h3>
				<div class="zhuangtai-box"><span>图文</span><span class="addtimee"></span><span v-text="shopxinxi.store_name"></span><span v-text="shopxinxi.hits">260</span><i><img src="../img-ninewei/icon_eye@3x.png"/></i></div>
				<!--<div class="model-tuwen" v-for="item in tuwenList">
					<h4 v-if="item[0]!=''"><img src="../img-ninewei/title-bg.png"/><p v-text="item[0]"></p></h4>
					<p v-text="item[1]"></p>
					<img class="twxq" :src="'http://www.ntyouxuan.com/'+item[2]" onerror="this.style.display='none'" />
				</div>-->
				{{tuwenList}}
				<div class="ts-footer">
					<p>到底了</p>
					<p>上滑去看看商品详情吧</p>
				</div>
				<div class="sltp" id="sltp"><img src="../img-ninewei/icon_arr@3x.png"/></div>
			</div>
		<div id="cover" @click="xiaochu()"></div>	
		<div id="guide" @click="guideimg()"><img src="../img/guide1.png"></div>
	</div>
</template>

<script>
	import nineweiNRcss from '../css/nineweiNR.css';
	import wx from 'weixin-js-sdk'
	
	var furl = "http://www.ntyouxuan.com/";
	export default{
		name:'nineweiNR',
		data () {
			return {
				userStute:0,
				user:"",
				tuwenList:{},
				shopxinxi:{},
				goods_id:0,
				scroll:"",
				scrollH:"",
				moveStute:false,
				id:'',
				scrollWatch:true,
				tiaozhuan:false,
				wxdata:{
					'appid':'',
					'timestamp':'',
					'wxnonceStr':'',
					'wxShal':'',
					'title':'',
					'title_desc':'',
					'link':'',
					'img_url':'',
				},
//				defaultImg: 'this.src="' + require('../img/kong.png') + '"'
			}
		},methods:{
			isWeiXin() {
		      let ua = window.navigator.userAgent.toLowerCase();
		      //mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko)version/9.0 mobile/13b143 safari/601.1
		      if (ua.match(/MicroMessenger/i) == 'micromessenger') {
		      return true;
		      } else {
		      return false;
		      }
		    },
			userpro:function(){
				this.id=this.$route.params.id;
				var self=this;
				var user='MTEyMTUyMzIzNDAwOTEzNjcyOTExMzM5NzU0NQ==';
				var stuta='1';
				if(user&&stuta){
					this.userStute=stuta;
					this.user=user;
					self.ajaxW(self.id,this.user);
				}
			},
			ajaxW:function(id,token){
				var self=this;
				$.ajax({
					type:"post",
					url:furl+"index.php?app=grade&act=fla_view_ajax",
					data:{"id":id,"token":token},
					dataType:"json",
					success:function(res){
						self.tuwenList=res.retval.detail;
						self.shopxinxi=res.retval.jwsj;
						self.goods_id=res.retval.jwsj.goods_id;
						
	        			self.addtimee=new Date(Number(res.retval.jwsj.add_time)*1000).Format("yyyy年MM月dd日 ");
						$(".addtimee").text(self.addtimee);
						
						self.wxdata.img_url=furl+res.retval.jwsj.lb_img;
		        		var turl=encodeURIComponent('nineweiNR/'+res.retval.jwsj.id);
		        		self.wxdata.link=furl+"newnt/index.html?url="+turl;
		        		self.wxdata.title='【农淘优选】'+res.retval.jwsj.title;
		        		self.wxdata.title_desc=res.retval.jwsj.wz_abstract;
					}
				});
			},
			menu1:function(){
				if(this.scrollWatch){
					this.scroll = document.getElementById("sltp").offsetTop;
					//欲诉到顶部的高度
					var windowH=$(window).height();
					//浏览器的高度
					var footerH=$(".nine-footer").height();
					//底部导航栏的高度
					var sltpH=$("#sltp").height();
					//元素本身的高度
					this.scrollH =document.body.scrollTop ||  document.documentElement.scrollTop;
					//页面滚动的距离
					if(this.scrollH+windowH>=this.scroll+footerH+sltpH){
						this.moveStute=true;
					}else{
						this.moveStute=false;
					}
				}
				
			},
			fxzy:function(){
				$("#cover").css("display","block")
				$("#guide").css("display","block")
				$("html,body").animate({scrollTop:0}, 500);
			},
			xiaochu:function(){
				$("#cover").css("display","none")
				$("#guide").css("display","none")
			},
			guideimg:function(){
				$("#cover").css("display","none")
				$("#guide").css("display","none")
			}
		},
		created:function(){
			this.userpro();
		},
		mounted:function(){
			
			
			var self=this;
			window.addEventListener("scroll",this.menu1);
			this.adurl=location.href;
			$.ajax({
				type:"post",
				url:furl+"index.php?app=ajax_third_login&act=wxjssdk",
				data:{'aurl':self.adurl},
				dataType:'json',
				success:function(res){
					if(res.done){
						self.wxdata.appid=res.retval.appid;
						self.wxdata.timestamp=res.retval.timestamp;
						self.wxdata.wxShal=res.retval.wxShal;
						self.wxdata.wxnonceStr=res.retval.wxnonceStr;
						if(self.isWeiXin()){
							self.wxConfig(wx,self.wxdata);
						}
						
					}
				}
			});
			var ninenr=document.getElementById("app-ninenr");
			var pageY;
			ninenr.addEventListener("touchstart",function(e){
				
				if(self.moveStute){
					
					pageY=e.touches[0].pageY;
				}
			});
			ninenr.addEventListener("touchmove",function(e){
				if(self.moveStute){
					
					var yz=e.touches[0].pageY;
					if(yz<pageY){
						var SLh=$("#sltp").height();
						if(SLh<$('#sltp img').height()){
							$("#sltp").height(SLh+1);
							var Hh=$(window).scrollTop();
							$(window).scrollTop(Hh+1);
							if(SLh>6){
								self.tiaozhuan=true;
							}
						}
						e.preventDefault();
					}else{
						var SLh=$("#sltp").height();
						$("#sltp").height(SLh-1);
						var Hh=$(window).scrollTop();
						$(window).scrollTop(Hh-1);
						e.preventDefault();
					}
				}
			});
			ninenr.addEventListener("touchend",function(){
				if(self.moveStute){
					$("#sltp").height("0.2rem");
					if(self.tiaozhuan){
						self.$router.push({name:'shopXQ',params:{id:self.goods_id}});
					}
				}
			});
			
			
			
			
			
		},
		destroyed:function () {
			console.log(111);
		    this.scrollWatch = false;
		}
	}
</script>

<style>
	#cover{width: 100%;height: 3000px; display:none;position:absolute;left:0;top:0;z-index:18888;background-color:#000000;opacity:0.7;}
	#guide{display:none;position:absolute;right:18px;top:5px;z-index:19999;}
	#guide img{width:260px;height:180px;}
</style>